//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "VolatilityCompositor.h"
using namespace Cephei::QL;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::CVolatilityCompositor::CVolatilityCompositor (boost::shared_ptr<QuantLib::VolatilityCompositor>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phVolatilityCompositor = NULL;
#endif
	_ppVolatilityCompositor = &childNative;
    
}
Cephei::QL::CVolatilityCompositor::CVolatilityCompositor (QuantLib::VolatilityCompositor& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phVolatilityCompositor = NULL;
#endif
	_ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (&childNative);
    
    _VolatilityCompositorOwner = owner;
    
}

Cephei::QL::CVolatilityCompositor::CVolatilityCompositor (CVolatilityCompositor^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phVolatilityCompositor = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (copy->GetShared());
        
    }
}
Cephei::QL::CVolatilityCompositor::CVolatilityCompositor (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phVolatilityCompositor = NULL;
#endif
	if (!t->IsSubclassOf(CVolatilityCompositor::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::CVolatilityCompositor::CVolatilityCompositor (QuantLib::Handle<QuantLib::VolatilityCompositor>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phVolatilityCompositor = &childNative;
	_ppVolatilityCompositor = &static_cast<boost::shared_ptr<QuantLib::VolatilityCompositor>>(childNative.currentLink());
    
    _VolatilityCompositorOwner = owner;
}
Cephei::QL::CVolatilityCompositor::CVolatilityCompositor (QuantLib::Handle<QuantLib::VolatilityCompositor> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phVolatilityCompositor = &childNative;
	_ppVolatilityCompositor = &static_cast<boost::shared_ptr<QuantLib::VolatilityCompositor>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::CVolatilityCompositor::CVolatilityCompositor (QuantLib::VolatilityCompositor childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phVolatilityCompositor = NULL;
#endif
	_ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (new QuantLib::VolatilityCompositor (childNative));
    
}
#endif

Cephei::QL::CVolatilityCompositor::~CVolatilityCompositor ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppVolatilityCompositor != NULL)
    {
	    delete _ppVolatilityCompositor;
        _ppVolatilityCompositor = NULL;
    }
}
Cephei::QL::CVolatilityCompositor::!CVolatilityCompositor ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppVolatilityCompositor != NULL)
    {
	    delete _ppVolatilityCompositor;
    }
}
QuantLib::VolatilityCompositor& Cephei::QL::CVolatilityCompositor::GetReference ()
{
    if (_ppVolatilityCompositor == NULL) throw gcnew NativeNullException ();
	return **_ppVolatilityCompositor;
}
boost::shared_ptr<QuantLib::VolatilityCompositor>& Cephei::QL::CVolatilityCompositor::GetShared ()
{
    if (_ppVolatilityCompositor == NULL) throw gcnew NativeNullException ();
	return *_ppVolatilityCompositor;
}
QuantLib::VolatilityCompositor* Cephei::QL::CVolatilityCompositor::GetPointer ()
{
    if (_ppVolatilityCompositor == NULL) throw gcnew NativeNullException ();
	return &**_ppVolatilityCompositor;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::VolatilityCompositor>& Cephei::QL::CVolatilityCompositor::GetHandle ()
{
	if (_phVolatilityCompositor == NULL)
	{
		_phVolatilityCompositor = new Handle<QuantLib::VolatilityCompositor> (*_ppVolatilityCompositor);
	}
	return *_phVolatilityCompositor;
}
#endif
bool Cephei::QL::CVolatilityCompositor::HasNative () 
{
	return (_ppVolatilityCompositor != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

